#include <pic.h>
#include <OSA.h>

unsigned char counter;

//------------------------------------------------------------------------------
void Task_T1 (void)
{
    for (;;)
    {
        OS_Delay(100);
        OS_SetBSem(0);
        counter++;
        OS_Yield();
        counter++;
        OS_WaitBSem(2);
    }
}


//------------------------------------------------------------------------------
void Task_T2 (void)
{
    for (;;)
    {
        OS_Delay(100);
        OS_SetBSem(1);
        counter++;
        OS_Yield();
        counter++;
        OS_WaitBSemTimeout(0, 100);
    }
}


//------------------------------------------------------------------------------
void Task_T3 (void)
{
    for (;;)
    {
        
        OS_Delay(100);
        OS_SetBSem(2);
        counter++;
        OS_Yield();
        counter++;
        OS_WaitBSemTimeout(1, 100);

    }
}


//------------------------------------------------------------------------------
void main (void)
{
    OS_Init();
    OS_CreateTask(1, Task_T1);
    OS_CreateTask(1, Task_T2);
    OS_CreateTask(1, Task_T3);


    for (;;)
    {
        asm(" CLRWDT ");
        OS_Timer();
        OS_Sched();
    }
}
